package com.beauty.dressing.module.main.adapter;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;

import com.beauty.dressing.common.bean.CourseBean;
import com.beauty.dressing.common.bean.GroupNavigation;
import com.beauty.dressing.common.bean.GuideList;
import com.beauty.dressing.module.common.adapter.CommonExpandWrapperAdapter;
import com.beauty.dressing.module.main.holder.CourseItemHolder;
import com.beauty.dressing.module.main.holder.GroupNavHolder;
import com.beauty.dressing.module.main.holder.GuideTeachHolder;


/**
 * 电影列表适配器
 *
 * @author xutingz
 * @email：xutingzhen@pkebu.com
 */
public class CourseListAdapter extends CommonExpandWrapperAdapter {

    public static class ViewType {
        public static final int COURSE_TITLE = 1;
        public static final int COURSE_ITEM = 2;
        public static final int COURSE_GUIDE_LIST = 3;
    }

    private int lastGroupIndex;

    public CourseListAdapter(Context context) {
        super(context);
    }

    public int getLastGroupIndex() {
        return lastGroupIndex;
    }

    public void setLastGroupIndex(int lastGroupIndex) {
        this.lastGroupIndex = lastGroupIndex;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
        super.onBindViewHolder(viewHolder, position);
    }

    @Override
    public int getItemViewType(int position) {
        Object o = getItem(position);
        if (o instanceof FixedViewInfo) {
            return ((FixedViewInfo) o).viewType;
        } else
        if (o instanceof GroupNavigation){
            return ViewType.COURSE_TITLE;
        } else if (o instanceof CourseBean){
            return ViewType.COURSE_ITEM;
        } else if (o instanceof GuideList){
            return ViewType.COURSE_GUIDE_LIST;
        }
        return super.getItemViewType(position);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        if (isHeader(viewType) || isFooter(viewType)) {
            return super.onCreateViewHolder(viewGroup, viewType);
        } else
        if (viewType == ViewType.COURSE_TITLE){
            return new GroupNavHolder(mContext,mLayoutInflater,viewGroup);
        } else if (viewType == ViewType.COURSE_ITEM) {
                CourseItemHolder holder = new CourseItemHolder(mContext, mLayoutInflater, viewGroup);
            return holder;
        } else if (viewType == ViewType.COURSE_GUIDE_LIST){
            return new GuideTeachHolder(mContext, mLayoutInflater, viewGroup);
        }
        return null;
    }

}
